def multiply(a, b):
    return a * b


print("a*b=", multiply(4, 5))


def changeInt(a):
    a = 10


b = 2
print(changeInt(b))
print(b)


# 可写函数说明
def changeme(mylist):
    "修改传入的列表"
    mylist.append([1, 2, 3, 4])
    print("函数内取值: ", mylist)
    return


# 调用changeme函数
mylist = [10, 20, 30]
print(mylist)
changeme(mylist)
print("函数外取值: ", mylist)


def user(name, age=18):
    print(age, name)


user(age=15, name='pp')
user(name='pp1')


# 星号
def args(arg, *arggs):
    print(arg)
    print(arggs)


args('ads', 55, 00, 99)


# 出现星号，必须指定传递参数 userInfo('明明', 'xm', 40,'xh') 会报错
def userInfo(arg, **vardit):
    print('输出：')
    print(arg)
    print(vardit)


userInfo('明明', a='xm', b=40, c='xh')
# 匿名函数
sum = lambda a, b: a + b

print('sum=', sum(3, 7))

# 变量作用域
tatol = 0


def sum(a, b):
    tatol = a + b
    print('局部：tatol=', tatol)


sum(10, 20)
print('全局：total=', tatol)

num = 1


def fun1():
    global num
    print(num)
    num = 10
    print(num)


fun1()
print('==========================')


def outer():
    num = 10

    def inner():
        nonlocal num  # nonlocal关键字声明
        num = 100
        print(num)

    inner()
    print(num)


outer()
print('***********************')
a = ['asd', 3, 4, 5, 6, 78, 8]
b = ('asd', 3, 4, 5, 6, 78, 8)


# print(type(a))
# print(type(b))
# list 当堆栈使用
def popa():
    if (len(a) >= 0):
        print(len(a))
        print(a.pop())
        print(a)
        popa()
    else:
        print('无数据了')


# popa()
def add(a):
    return a + 3


print('===========')
vec = [2, 3, 4, 5, 6]
print([[x, x ** 2] for x in vec])
print([3 * x for x in vec])
print([add(x) for x in vec])

# 矩阵变化
print('*****************8')
matrix = [
    [1, 2, 3, 4],
    [5, 6, 7, 8],
    [9, 10, 11, 12],
]
transposed = []
for row in matrix:
    print('start')
    print(row)
    print('end')
for i in range(4):
    print(i)
    print(transposed)
    transposed.append([row[i] for row in matrix])
#print([[[i, row[i]] for row in matrix] for i in range(4)], end='\n')
print('*************')

keyvalue={'gallahad': 'the pure', 'robin': 'the brave'}
for k,v in keyvalue.items():
    print(k,v)
